//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: core.h 817 2007-08-24 16:31:08Z roger $
//

#ifndef __CORE_H
#define __CORE_H

#include <config.h>

#include <iml/SunIM.h>
#include <unihan_im.h>

#include "unihan_property.h"

typedef struct _IMConfigList {
        char *key;
        char *value;
        struct _IMConfigList *next;
} IMConfigList;

typedef enum {
    STATUS_STARTED  = 1 << 0,
    PREEDIT_STARTED = 1 << 1,
    LOOKUP_STARTED  = 1 << 2
} UnihanStartedFlags;
#define is_status_started(flags)  (flags & STATUS_STARTED)
#define is_preedit_started(flags) (flags & PREEDIT_STARTED)
#define is_lookup_started(flags)  (flags & LOOKUP_STARTED)

typedef struct {
    UnihanStartedFlags aux_started;

    void *keyhandler_data;
    void *im_manager_data;
    void *phrase_data;

    UnihanTCSCMode tcsc;
    int phrase_mode;

    char *username;
    char *hostname;
    char *protocol_type;
    char *client_type;
    char *display_id;
    char *os_name;
    char *os_version;
    char *os_arch;

    IMConfigList **imConfig;

#if TIMEBOMB
    int expired;
#endif
} DataPerDesktop;

typedef struct {
	int created;
	void *data;
} UserDataTable;

typedef struct _UnihanRegisteredIMArg UnihanRegisteredIMArg, *UnihanRegisteredIMList;

struct _UnihanRegisteredIMArg{
	char *imid;
	UnihanPropertyList *prop_list;
	UnihanRegisteredIMList next;
};

typedef enum {
    PHRASE_STATE_NEVER = 0,
    PHRASE_STATE_IDLE = 1,
    PHRASE_STATE_SELECTING = 2,
} UnihanPhraseState;

typedef struct {
    UnihanStartedFlags ui_started;
    char *locale;
    int lookup_cands_per_page;

	int conv_on;

#if 0
	UnihanPropertyArgList currIMprop_list;
#endif

#if NEW_PROPERTY
#else
	int fullwidth;

	int puncce;	/* 2004.2.11 arren */
	int shuangpin;	/* 2994.2.19 arren */
#endif
		
	void *currIM;
	int punctuation;
	int us_kbd;
	int us_kbd_caps_pressed;
	int us_kbd_shift_pressed;
	
	int shift_key_state;
	UnihanPhraseState phrase_state;

	UserDataTable *userData;

	void *phrase_data;
} DataPerSession;

void conversion_on(iml_session_t *s);
void conversion_off(iml_session_t *s);
void conversion_temp_on(iml_session_t *s);
void conversion_temp_off(iml_session_t *s);

void im_manager_init(iml_desktop_t *d);
void im_manager_done(iml_desktop_t *d);
int im_manager_get_num_im(iml_desktop_t *d);
void im_manager_create_session(iml_session_t *s);
void im_manager_destroy_session(iml_session_t *s);
void im_manager_get_im_list(iml_session_t *s, IMAuxDrawCallbackStruct *aux);
void im_manager_set_default_im(iml_session_t *s, char *imid);

const char *im_get_curr_im_name(iml_session_t *s);
int im_propagate_focus_event(iml_session_t *s, int focused);
int im_propagate_key_event(iml_session_t *s, IMKeyListEvent *ev);
int im_propagate_lookup_page_turn_event(iml_session_t *s, int direction);
int im_propagate_lookup_select_event(iml_session_t *s, int num);
void im_change_to_next_im(iml_session_t *s);
void im_change_to_next_im1(iml_session_t *s);
void im_change_to_prev_im(iml_session_t *s);
void im_change_to_prev_im1(iml_session_t *s);
void im_change_to_im(iml_session_t *s, char *imid);

#if 0
UnihanPropertyArgList im_get_current_im_props(iml_session_t *s);
UnihanPropertyArgList im_get_runtime_property(iml_session_t *s,
		UnihanRuntimePropertyType type,
		int name);
void im_update_property_list(iml_session_t *s,
		UnihanPropertyArgList plist);
void im_set_property_list(iml_session_t *s,
		UnihanPropertyArgList prop_list);
void destroy_im_property(UnihanPropertyArgList plist);

int convert_props_to_string(iml_session_t *s,
		UnihanPropertyArgList prop_list,
		int num_props,
		int int_values[],
		UTFCHAR* string_values[]);
int convert_string_to_props(int int_values,
		char* string_values,
		UnihanPropertyArgList *prop_list);

void im_set_width(iml_session_t *s, int is_full);
void im_set_puncce(iml_session_t *s, int is_CH);
void status_update_width(iml_session_t *s, int is_full);
void status_update_puncce(iml_session_t *s, int is_CH);
UnihanPropertyArgList properties_dup(UnihanPropertyArgList proplist);
#endif

#if NEW_PROPERTY
char *im_get_curr_im_id(iml_session_t *s);
void toggle_property(iml_session_t *s, char* key);
void register_im_property(iml_session_t *s, char* imid);
void destroy_im_properties(UnihanPropertyList *prop_list);
int convert_props_to_string(iml_session_t *s,
							UnihanPropertyList *prop_list,
							int int_values[],
							UTFCHAR* string_values[]);
							
#else
void check_fullwidth(iml_session_t *s);
void check_puncce(iml_session_t *s);
void toggle_width(iml_session_t *s);
void toggle_puncce(iml_session_t *s);
#endif

void check_module_info(iml_session_t *s);
void tcsc_set(iml_session_t *s, UnihanTCSCMode tcsc);

void toggle_punctuation_keyboard(iml_session_t *s);
void toggle_us_keyboard(iml_session_t *s);

void im_config_change(iml_session_t *s, char *imid, char *key, char *val);
IMConfigList *im_config_get(iml_session_t *s, char *imid);

void im_set_symbol_user_table(iml_session_t *s,
		int numSut,
		SymbolUserTable *sut);
void im_set_word_user_table(iml_session_t *s,
		int numWut,
		WordUserTable *wut);
void im_config_unispim(iml_session_t *s,int count_values,int unispim_values[]);

#if TIMEBOMB
int check_expired(iml_desktop_t *d);
void notify_timebomb(iml_session_t *s);
void notify_expired(iml_session_t *s);
#endif

extern UTFCHAR lename_string[];
extern UTFCHAR aux_name[];

#endif /* __CORE_H */

// vi:ts=4:sw=4:nowrap:cin:expandtab
